
(function(){
	// 畅龙 2008
	//var isLoaded	= false;
	if( isLoaded ){
		return false;
	}
	isLoaded	= true;
	var top;
	var onFullScreen	= function(){
		top	= $('html').scrollTop;
		$('arrow').setStyle('display', 'none' );
		$('html').setStyle('overflow-y', 'hidden');
		$('html').scrollTop	= 0;
	}
	var onNormalScreen	= function(){
		$('arrow').setStyle('display', 'block');
		$('html').setStyle('overflow-y', 'scroll');
		$('html').scrollTop	= top;
	}

	window.AddEditor	= function (oEditorId, id, tid, iid, k, v){
		setTimeout(function(){
			if( $(id).getParent('td') ){
				$(id).getParent('td').addClass('oEditor');
			}
		}, 400);
		var oEditor	= window[oEditorId]	= new InnovaEditor(oEditorId);

		oEditor.width		= '100%';
		oEditor.css			= _RootDir + "/_admin/src/img/_editor.css";

		oEditor.height		= 340;
		if( Browser.Engine.trident ){
			oEditor.height	-= 65;
		}

		oEditor.cmdAssetManager = "modalDialogShow('" + _RootDir + "/_res/_editor/assetmanager/assetmanager.php?tid="+tid+"&iid="+iid+"&k="+k+"&v="+v+"',640,480)";
		//oEditor.cmdInternalLink	= "modelessDialogShow('links.htm',365,280)";
		//oEditor.cmdCustomObject = "modelessDialogShow('objects.htm',365,270)";


		//oEditor.btnPrint	= true;
		oEditor.btnPasteText	= true;
		oEditor.btnPasteWord	= false;

		oEditor.btnFlash	= true;
		oEditor.btnMedia	= true;
		//oEditor.btnLTR		= true;
		//oEditor.btnRTL		= true;
		//oEditor.btnSpellCheck	= true;
		//oEditor.btnStrikethrough= true;
		oEditor.btnSuperscript	= true;
		oEditor.btnSubscript	= true;
		oEditor.btnClearAll	= true;
		//oEditor.btnSave		= true;
		//oEditor.btnStyles	= true; //Show "Styles/Style Selection" button

		oEditor.customColors	= ["#ff4500","#ffa500","#808000","#4682b4","#1e90ff","#9400d3","#ff1493","#a9a9a9"];
		oEditor.mode		= "XHTMLBody";
		oEditor.onFullScreen	= onFullScreen ;
		oEditor.onNormalScreen	= onNormalScreen ;
		oEditor.REPLACE(id);

		var Timer1;
		$(id).getParent('form').addEvent('reset', function(){
			$clear(Timer1);
			Timer1	= setTimeout( function(){
				oEditor.loadHTML( $(id).value );
			}, 100);
		});

		if( _Debug ){
			setTimeout(function(){
				var oWin	= document.getElementById("idContent" + oEditor.oName).contentWindow;
				var oWord	= document.getElementById("idContentWord" + oEditor.oName).contentWindow;

				//alert( oWin.frameElement ==  document.getElementById("idContent" + oEditor.oName) )
				// alert( oEditor.doOnPaste )	contentEditable	pasteHTML

				with( oWin.document.body ){
					attachEvent("onpaste", function(evt){
						try{
							alert( clipboardData.getData('Text') )
							evt.cancelBubble = true;
							evt.returnValue	 = false;

							var oSel	=	oWin.document.selection.createRange();
								oWord.document.designMode="on";
								oWord.document.open("text/html","replace");
								oWord.document.write("<html><head></head><body></body></html>");
								oWord.document.close();
								oWord.document.body.contentEditable	= true;
								oWord.focus();
								oWord.document.execCommand("SelectAll");
								oWord.document.execCommand("Paste");
								var sHTML	= oWord.document.body.innerHTML ;
								alert( sHTML )
								RegMaps.each(function(reg){
									sHTML	= sHTML.replace(reg, "<p>");
								});
								sHTML=fixPathEncode(sHTML);
								oWord.document.body.innerHTML	=	sHTML;    
								fixPathDecode(oWord);
								oSel.pasteHTML( sHTML );
						}catch(err){
							alert(err)
						}
					});
				}
			}, 300);
		}
	}
	
	window.sEditorPath	=  _RootDir + '/_res/_editor/scripts/';
	if(navigator.appName.indexOf('Microsoft')!=-1){
		document.write("<scr"+"ipt src='" + window.sEditorPath + "editor.js'></scr"+"ipt>");
	}else{
		document.write("<scr"+"ipt src='" + window.sEditorPath + "moz/editor.js'></scr"+"ipt>");
	}
	var RegMaps	= ['<br\\s*\\/?>\\s*<br\\s*\\/?>\s*' ,
					'<br\\s*\\/?>(\\s*\\&nbsp\\;\\s*)+<br\\s*\\/?>(\\s*\\&nbsp\\;\\s*)+' ,
					'<p>\\s*　\\s*　\\s*' ,
					'<p>(\\&nbsp\\;\\s?)+' ,
					'<p>\\s+' ] . map( function(val){
			return new RegExp(val, "gi");
	});
})();
